<?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
 * Framework_Meta
 *
 * @author      Ian Szewczyk <roamzero@gmail.com>
 * @copyright   (c) 2007 Ian Szewczyk. All rights reserved.
 * @license     http://www.opensource.org/licenses/bsd-license.php
 * @package Framework
 * @filesource
 */


/**
 * Framework_Meta
 *
 * This class is used as a loader to get specific Meta classes,
 * the purpose of which are to gather, save, and query data about
 * other parts of the framework, namely Modules and Components.   
 *
 * @author Ian Szewczyk <roamzero@gmail.com>
 * @package Framework
 */
abstract class Framework_Meta
{
	/**
	 * $instances
	 *
	 * @access 		private
	 * @var 		array 		$instances
	 * @static
	 */
	static private $instances = array();

	/**
	 * factory
	 *
	 * @access 		public
	 * @param 		string 		$meta 		Name of the meta handler to load
	 * @return 		mixed 		Instance of Framework_Meta_Common, PEAR_Error
	 * @static
	 */
	static public function factory($meta = 'Module')
	{

		if (!array_key_exists($meta,self::$instances)) {

			$file = 'Framework/Meta/'.ucfirst($meta).'.php';
			if (!include_once($file)) {
				return PEAR::raiseError('Could not load Meta file: '.$file);
			}
	
			$class = 'Framework_Meta_'.ucfirst($meta);
			if (!class_exists($class)) {
				return PEAR::raiseError('Could not find Meta class: '.$class);
			}
	
			try {
				$instance = new $class($params);
				if (!$instance instanceof Framework_Meta_Common) {
					return PEAR::raiseError('Meta class must extend from Framework_Meta_Common');
				}
			} catch (Framework_Exception $error) {
				return PEAR::raiseError($error->getMessage());
			}
			self::$instances[$meta] = $instance;
			return $instance;
		} else {
			return self::$instances[$meta];
		}


	}
}

?>
